package com.yztstudy.filter;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.yztstudy.dto.UserDTO;
import com.yztstudy.entity.User;
import com.yztstudy.utils.RedisConstants;
import com.yztstudy.utils.UserHolder;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 登录拦截器
 */

public class LoginInterceptor implements HandlerInterceptor {

    /**
     * 前置拦截
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        // TODO 1.判断ThreadLocal是否有用户，有就放行，没有就拦截
        if (UserHolder.getUser() == null)
        {
            response.setStatus(401);
            return false;
        }
        return true;
    }

}
